package main

import (
	"fmt"
	"math"
)

var (
	reverseStringTest = []byte{'h', 'e', 'l', 'l', 'o'}
	reverseTest       = -1534236469
)

func testString() {
	fmt.Println(reverse(reverseTest))
	return

	fmt.Println(reverseStringTest)
	reverseString(reverseStringTest)
	fmt.Println(reverseStringTest)
}

// Section 2 -- Strings
func reverse(x int) int {
	if x > math.MaxInt32 || x < math.MinInt32 {
		return 0
	}

	y := 0
	for x != 0 {
		y = y*10 + x%10
		x = x / 10
	}

	if y > math.MaxInt32 || y < math.MinInt32 {
		return 0
	}

	return y
}

func reverseString(s []byte) {
	j := len(s) - 1
	i := 0
	for i < j {
		s[i], s[j] = s[j], s[i]
		j--
		i++
	}
}
